using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Evolution.Engine.Objects;
using Microsoft.Xna.Framework.Input;
using Evolution.Engine.Managers;
using Evolution.Engine.Utilities;

namespace Evolution.GUI.Components
{
    public class ImageButton : Pushbutton
    {
        private Texture2d _Selected;
        private Texture2d _Hover;
        private Texture2d _Normal;

        public Texture2d Normal { get { return _Normal; } set { _Normal = value; } }
        public Texture2d Hover { get { return _Hover; } set { _Hover = value; } }
        public Texture2d Selected { get { return _Selected; } set { _Selected = value; } }
        
        public ImageButton(string Name, string Text, string PushedAsset, string NormalAsset, Form Parent, Vector2 Position, Vector2 Size)
            : base(Name, Text, PushedAsset, NormalAsset, Parent, Position, Size)
        {
            
        }

        public void SetImage(string NormalAsset, string HoverAsset, string SelectedAsset)
        {
            _Normal = new Texture2d(_Location, GameUtils.ConvertToVector(_Size), NormalAsset);
            _Hover = new Texture2d(_Location, GameUtils.ConvertToVector(_Size), HoverAsset);
            _Selected = new Texture2d(_Location, GameUtils.ConvertToVector(_Size), SelectedAsset);

            _Normal.LoadContent();
            _Hover.LoadContent();
            _Selected.LoadContent();

            SetLocation();
        }

        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);

            switch (_State)
            {
                case ButtonState.Pressed:
                    _Selected.Draw(gameTime);
                    break;
                
                case ButtonState.Released:
                    _Normal.Draw(gameTime);
                    break;
                
                default:
                    if (Bounds.Contains(InputManager.Instance.CurrentMousePoint))
                        _Hover.Draw(gameTime);
                    break;
            }
        }

        public override void SetLocation()
        {
            base.SetLocation();

            _Normal.Position = _Parent.Location + _Location;
            _Hover.Position = _Parent.Location + _Location;
            _Selected.Position = _Parent.Location + _Location;
        }
    }
}
